<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/weui.min.css">
<title>肯同OA系统登录</title>
<style>
body,html{overflow:hidden;font-family:"微软雅黑"}
input{font-family:"微软雅黑";}
body{background-color:#fbf9fe}
.page_desc{text-align:center;color:#888;font-size:14px}
.hd{padding:2em 0; text-align:center}
.hd img{height:100px;width:100px;border-radius:50px}
.weui_label{width:80px;font-weight:700}
.weui_cell:before{
	left:0;
}
.weui_cell{
	padding:12px 15px;
}
label{
margin-bottom:0

}
p.opt_link a:link{
	font-weight:200;
}
</style>
</head>
<body>
	<div  style="padding: 2em 0 1em 0; text-align: center;">
		<div><a href="/"><img src="__PUBLIC__/images/logo.png" style="height:3em"></a></div>
	</div>
	<form role="form" data-check="/login/vali" method="post">
	<div class="weui_cells weui_cells_form">
	    <div class="weui_cell">
			<div class="weui_cell_hd"><label class="weui_label">用户名</label></div>
			<div class="weui_cell_bd weui_cell_primary">
				<input class="weui_input"  name="uname" id="uname"  type="text" maxlength="20" placeholder="工号/手机号/企业邮箱">
			</div>
		</div>
		<div class="weui_cell">
			<div class="weui_cell_hd"><label class="weui_label">密码</label></div>
			<div class="weui_cell_bd weui_cell_primary">
				<input class="weui_input"  type="password"  name="pwd" id="pwd" placeholder="请输入密码">
			</div>
		</div>
		<div class="weui_cell">
			<label style='font-size:14px; font-weight:normal; '><input type='checkbox' id='mindPwd' name=''/> 记住密码</label>
		</div>
	</div>
	<div class="weui_btn_area">
		<input class="weui_btn weui_btn_primary" type="button" onclick="checkUser()" value="登录">
	</div>
	</form>
	<div style="margin: .5em 15px 0em;">
		<p class="opt_link"> 
			<a style="font-weight:600;color:#9f2925;" href="{:U('ctrl/losspwd')}">忘记密码？</a> | 
			<a style="font-weight:600;color:#9f2925;" href="{:U('ctrl/register')}">注册一个新账号</a>
		</p>
	</div>
	<script src="__PUBLIC__/js/jquery-1.8.3.min.js"></script>
	<script>
		$(function() {
			$("#uname").val(getCookie("username"));
			$("#pwd").val(getCookie("password"));
			optErrMsg();
			
		});
		$("#errMsgContiner").hide();
		function optErrMsg() {
			$("#showErrMsg").html('');
			$("#errMsgContiner").hide();
		}

		//输入框按下回车
		function randCodeKeyDown() {
			var lKeyCode = (navigator.appname == "Netscape") ? event.which
					: window.event.keyCode; //event.keyCode按的建的代码，13表示回车
			if (lKeyCode == 13) {
				checkUser();
			} else {
				return false;
			}
		}

		//验证用户信息
		function checkUser() {
			if (!validForm()) {
				return false;
			}
			Login();
		}
		//表单验证
		function validForm() {
			if ($.trim($("#uname").val()).length == 0) {
				js.wx.alert("请输入用户名");
				return false;
			}

			if ($.trim($("#pwd").val()).length == 0) {
				js.wx.alert("请输入密码");
				return false;
			}
			
			//       if($.trim($("#randCode").val()).length==0){
			//         showErrorMsg("请输入验证码");
			//         return false;
			//       }
			//存储cookie
 			if($("#mindPwd").is(":checked")){
 				setCookie("username", $("#uname").val(), 7);
 				setCookie("password", $("#pwd").val(), 7)
 			}
			return true;
		}
		function setCookie(c_name, value, expiredays) {
			var exdate = new Date();
			exdate.setDate(exdate.getDate() + expiredays);
			document.cookie=c_name+"="+escape(value)+((expiredays == null)?"":";expires="+exdate.toGMTString());
		}
		function getCookie(c_name) { 
			if (document.cookie.length>0) {
				c_start=document.cookie.indexOf(c_name + "=")  
				if (c_start!=-1) {  　　
					c_start=c_start + c_name.length+1;　　
					c_end=document.cookie.indexOf(";",c_start) ;　　
					if (c_end==-1) c_end=document.cookie.length; 　　 
					return (document.cookie.substring(c_start,c_end));  
				}
			} 
			return "";
		}
		//登录处理函数
		function Login() {
			var checkurl = $('form').data('check');//验证路径
			var formData = new Object();
			var data = $(":input").each(function() {
				formData[this.name] = $("#" + this.name).val();
			});
			$.ajax({
				async : false,
				cache : false,
				type : 'POST',
				url : checkurl,// 请求的action路径
				data : formData,
				error : function() {// 请求失败处理函数
					js.wx.alert("服务器访问失败！");
				},
				success : function(d) {					
					if (d.errcode == 0) {
						window.location.href = "/m/index";
					} else {
						js.wx.alert(d.errmsg);
					}
				}
			});
		}
	</script>
</body>
</html>
